import clone from 'src/utils/clone'

const CACHE = Symbol('CACHE')

class CacheStorage {
  [CACHE] = {}
  get length () {
    return Object.keys(this[CACHE]).length
  }
  key (index) {
    return this[CACHE][index]
  }
  getItem (key) {
    return key ? clone(this[CACHE][key]) : void 0
  }
  setItem (key, value) {
    this[CACHE][key] = clone(value)
  }
  removeItem (key) {
    delete this[CACHE][key]
  }
  clear () {
    this[CACHE] = {}
  }
}
export default CacheStorage
